package deom5;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2023-04-08
 * Time: 8:49
 **/
 class ListNode {
       int val;
       ListNode next;
       ListNode(int x) {
          val = x;
          next = null;
      }
 }
public class test15 {
    public boolean hasCycle(ListNode head) {
          ListNode fast = head;
          ListNode slow = head;
          while (fast != null && fast.next != null){
              fast = fast.next.next;
              slow = slow.next;
              if(slow == fast){
                  return true;
              }
          }
          return false;
    }
}
